<?PHP global $OnePress; global $current_user; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<?PHP wp_head() ?>
</head>
<body class="<?PHP echo $OnePress->layout->classname; ?>">
<div id="page">
	<?PHP do_action('op_header'); ?>
	<?PHP do_action('op_welcome'); ?>
	<?PHP do_action('op_navigation'); ?>
<?PHP

function op_favicon()
{
	echo '<link rel="icon" type="image/x-icon" href="/favicon.ico" />';
}

function op_feeds(){
	echo "\n".'<link rel="alternate" type="application/rss+xml" title="'; bloginfo('name'); echo' RSS Feed" href="'; echo bloginfo('rss2_url'); echo '" />';
	echo "\n".'<link rel="alternate" type="application/atom+xml" title="'; bloginfo('name'); echo' Comments RSS Feed" href="'; echo bloginfo('comments_rss2_url'); echo '" />';
	echo "\n".'<link rel="pingback" href="'; bloginfo('pingback_url'); echo '" />';	
}

function op_meta_title()
{
    echo '<title>'; 
	bloginfo('name');
	wp_title(' &raquo; ', true, 'left');
	echo '</title>';
}

function op_meta_description()
{
	echo '<meta name="description" content="';
	if ( is_single() ) { 
		wp_title(''); 
		echo ' - '; } 
	elseif ( is_page() ) { 
		wp_title(''); 
		echo ' - '; } 
	bloginfo('description');
	echo '" />';	
}

function fix_ie()
{
	echo <<<EOS
<!--[if lt IE 8]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
<![endif]-->
EOS;
}

function op_header()
{
	?>
	<div id="header">
		<div class="hd"><div class="c"></div></div>
	  	
		<?PHP
		
			// Get user defined image
			if (($current_img = get_option('op_theme_header_img')) && $current_img != 0){
				if($files = wp_get_attachment_image_src($current_img, 'full')){
					$header_img = $files[0];
					$style = ' style="background: url(\''.$header_img.'\');"';
				}
			}
			else $style = '';
			
			echo '<div class="bd"><div class="c"'.$style.'>';
		?>
		<div id="headerimg" class="s">
		<?PHP do_action('op_header_content'); ?>
		</div>
		</div></div>
		<div class="ft"><div class="c"></div></div>
	</div>
	<?PHP
}

function op_header_content()
{
	?>
	<h1><a href="<?php echo get_option('home'); ?>/"><span><?php bloginfo('name'); ?></span></a></h1>
	<div class="description"><span><?php bloginfo('description'); ?></span></div>
	<div id="headerlink"><a href="<?php echo get_option('home'); ?>/"><span></span></a></div>
	<?PHP
}

function op_welcome()
{
	global $current_user; 	

	if(get_option('users_can_register') == 1){
		echo '<div id="welcome">';		
		// need to know WordPress version as certain helpers did not exist until 2.6 or 2.7
		global $wp_version;
		preg_match('/([0-9\.]+)/',$wp_version,$version);
		
		$redirect_to = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		if($current_user->display_name == NULL){
			if($version[0] >= 2.7){ // use wp_login_url as it provides redirect helper
				$login_link = '<a href="'.wp_login_url().'?redirect_to='.$redirect_to.'">'.__('login').'</a>';
				$register_link = '<a href="'.site_url('wp-login.php?action=register', 'login').'">'.__('register').'</a>';
			}
			else if($version[0] >= 2.6){ // use site_url as it will for https:// if necessary
				$login_link = '<a href="'.site_url('wp_login.php', 'login').'">'.__('login').'</a>';
				$register_link = '<a href="'.site_url('wp-login.php?action=register', 'login').'">'.__('register').'</a>';
			}
			else{ // backward compatibility
				$login_link = '<a href="' . get_option('siteurl') . '/wp-login.php">' . __('login') . '</a>';
				$register_link = '<a href="' . get_option('siteurl') . '/wp-login.php?action=register">' . __('register') . '</a>';
				
			}
			echo '<p><span>Welcome, please '.$login_link.' or '.$register_link.'</span></p>';
		} 
		else{ 
			echo '<p>';
			if($version[0] >= 2.7){
				$user_link = '<a href="'.site_url('/wp-admin/profile.php', 'admin').'">'.$current_user->display_name.'</a>';
				$logout_link = '<a href="'.wp_logout_url().'">'.__('logout').'</a>';
			}
			else if($version[0] >= 2.6){
				$user_link = '<a href="'.site_url('/wp-admin/profile.php', 'admin').'">'.$current_user->display_name.'</a>';
				$logout_link = '<a href="'.site_url('/wp-login.php?action=logout', 'admin').'">'.__('logout').'</a>';
			}
			else{
				$user_link = '<a href="'.get_option('siteurl') . '/wp-admin/profile.php">'.$current_user->display_name.'</a>';
				$logout_link = '<a href="' . get_option('siteurl') . '/wp-login.php?action=logout">' . __('logout') . '</a>';
			}
			
			printf(__('Welcome back, %1$s!  %2$s'), $user_link,$logout_link);
			echo '</p>';
		}
		echo '</div>';
 	}
}

function op_navigation()
{
	OP::default_nav();
}



?>